//
//  DataManager.m
//  DemoPlus
//
//  Created by 王力 on 15/8/8.
//  Copyright © 2015年 王力. All rights reserved.
//

#import "DataManager.h"

#define NEED_GUIDE_VIEW_VERSION @"1"

static NSString *KeyUserLevel = @"userLevel";
static NSString *KeyGuideVersion = @"firstLaunch";
static NSString *KeyUserName = @"userName";

@implementation DataManager
// 获取使用实例
+ (instancetype )sharedInstance
{
    static DataManager *sharedInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedInstance = [[super alloc] init];
        [sharedInstance initManager];
    });
    return sharedInstance;
}
// 初始化Manager
- (void) initManager
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    self.userLevel = [userDefaults objectForKey:KeyUserLevel];
    self.showGuideView = [userDefaults boolForKey:KeyGuideVersion];
    self.screenSize = [[UIScreen mainScreen] bounds].size;
}
// 保存用户名
- (void)setCurrentUserName:(NSString *) userName{
    self.userName = userName;
    dispatch_async(dispatch_get_main_queue(), ^{
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setObject:self.userName forKey:KeyUserName];
        [userDefaults synchronize];
    });
}
// 是否显示引导页
- (void) setCurrentGuideView:(BOOL) showGuideView{
    self.showGuideView = showGuideView;
    dispatch_async(dispatch_get_main_queue(), ^{
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setBool:showGuideView forKey:KeyGuideVersion];
        [userDefaults synchronize];
    });
}
@end
